home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14457 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.mcs.net!usenet
  2. From: mikey@mcs.com (Mike Young)
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user)
  5. Date: 31 Mar 1996 10:27:49 GMT
  6. Organization: Fen Software, Inc.
  7. Message-ID: <4jlmn5$h1k@Nntp1.mcs.net>
  8. References: <wnewmanDoxrCp.DKv@netcom.com> <Dp1oAw.7Cz@world.std.com> <EACHUS.96Mar29191146@spectre.mitre.org>
  9. NNTP-Posting-Host: mikey.pr.mcs.net
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=US-ASCII
  12. X-Newsreader: WinVN 0.99.6
  13.  
  14. In article <EACHUS.96Mar29191146@spectre.mitre.org>, eachus@spectre.mitre.org> 
  15. says...
  16. >some tools over the code.  The choice was between Ada and a shell
  17. >script...I chose Ada:
  18. >
  19. >generic
  20. >  with procedure To_Do(File: in String);
  21. >procedure Iterate_Files(Pattern: in String := "*";
  22. >                        Directory: in String := "");
  23. >-- This generic iterates over all files in a directory matching Pattern and
  24. >-- calls To_Do once for each such directory entry.  If a file has several
  25. >-- links in the directory To_Do will be called once for each.
  26.  
  27. =========
  28. I don't know about that, Robert. The equivalent shell script would be:
  29.  
  30. #---- iterateFiles
  31. fileop=$1;shift
  32. for file in $*; do $fileop $file; done
  33.  
  34. You would call it thusly:
  35.  
  36.   iterateFiles 'head -n 3' *.ada >header.comments
  37.  
  38. or, directly, without a script:
  39.   for file in *.ada; do head -n 3 $file; done >header.comments
  40.  
  41. or, in Windows NT or 95:
  42.   for %i in (*.ada) do gnatchop -s -w %i
  43.  
  44. You are not restricted to procedures in that same program, all system utilities 
  45. are directly available, you don't need to rebuild to add new features, and you 
  46. need not have bothered with your 50 lines of code. All are big wins, IMO. You 
  47. can always write small, easy to maintain, helper programs if available 
  48. utilities don't do what you need.
  49.  
  50. >
  51. >
  52. >   Two observations.  First, the generic procedure approach is
  53. >certainly right for this case.  Second, the VADS run-time provided a
  54. >call for freeing A_Strings, but not for find_files.find_file_rec, so I
  55.  
  56. ===========
  57. Hmmm.
  58.  
  59. Mike.
  60.  
  61.